Frames and Iframes

Frames

HTML frames are used to divide your browser window into multiple sections where each section can load a separate HTML document. A collection of frames in the browser window is known as a frameset. The window is divided into frames in a similar way the tables are organized: into rows and columns.


Disadvantages of Frames

There are few drawbacks with using frames, so it's never recommended to use frames in your webpages −

1.Some smaller devices cannot cope with frames often because their screen is not big enough to be divided up.

2.Sometimes your page will be displayed differently on different computers due to different screen resolution.

3.The browser's back button might not work as the user hopes.

3.There are still few browsers that do not support frame technology.


Note:

HTML <frame> tag is not supported in HTML5.Instead <iframe> tag is used.


HTML Iframes

An HTML iframe is used to display a web page within a web page.


HTML Iframe Syntax

The HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.


Syntax:

<iframe src="url" title="description">


Iframe - Set Height and Width

Use the height and width attributes to specify the size of the iframe.


Example:

<iframe src="demo_iframe.htm" height="200" width="300" title="Iframe Example"></iframe>


Iframe - Remove the Border

By default, an iframe has a border around it.

To remove the border, add the style attribute and use the CSS border property


Example:

<iframe src="demo_iframe.htm" style="border:none;" title="Iframe Example"></iframe>


Iframe - Target for a Link

An iframe can be used as the target frame for a link.

The target attribute of the link must refer to the name attribute of the iframe.


Example:

<iframe src="demo_iframe.htm" name="iframe_a" title="Iframe Example"></iframe>

<p><a href="https://www.w3schools.com" target="iframe_a">W3Schools.com</a></p>